<%@ page language="java" contentType="application/vnd.ms-excel; name='member'; charset=UTF-8" pageEncoding="UTF-8"  import="java.util.*,common.*,java.sql.*,db.*"%>
<%
response.setHeader("Content-Disposition", "inline; filename=ent_test.xls"); // 파일 이름 지정
response.setHeader("Content-Description", "JSP Generated Data");
%>    
<%
		request.setCharacterEncoding("utf-8");
		
		String member_test_code 		= "";
		String member_id 		= "";
		String test_state 		= "";
		String test_state_str 		= "";
		String test_state_holding = "";
		String login_id_map 		= "";
		String login_name 	= "";
		String email	= "";
		String cell_no	= "";
		String result_code	= "";
		
		String sign_date 		= "";
		String sign_state 		= "";
		
		String rater_id	= "";
		String rating_state	= "";
		String rating_start_time	= "";
		String rating_close_time	= "";
		String rating_reg_dt	= "";
		
		String rerating_member_test_code	= "";
		String rerating_gubun	= "";
		String rerating_reason	= "";
		
		String r_num="";
		
		String ent_nm="";
		String reg_dt 	= "";
		
		String pause_yn="";
		String test_break_yn="";
		
		String rating_true="";
		String end_dt="";
		
		String opic_gubun="";
		String member_dist_str="";
		
		String rating_grade = "";
		String part_total = "";
		        
        UserSession userSession = (UserSession)session.getAttribute("user"); 
		
        String login_id = null;
		String user_id = null;
		String level = null;
		String ent_id = null;
		
		user_id = CommonUtil.nvl(request.getParameter("user_id"));
		ent_id = CommonUtil.nvl(request.getParameter("ent_id"));

		if(userSession!= null){
			login_id = userSession.getLogin_id();
			level = userSession.getAdmin_level();
			
			if(user_id.equals("")){
				user_id = userSession.getUser_id();
			}
			
			if(ent_id.equals("") && level.equals("5")){
				ent_id = userSession.getEnt_id();
			}
			
		}
		
		System.out.println("user_id====>" + user_id);
		System.out.println("level====>" + level);
		
		String start_date	= CommonUtil.nvl(request.getParameter("start_date"),""); 
		String end_date	= CommonUtil.nvl(request.getParameter("end_date"),"");		
		
		String search_combo = CommonUtil.nvl(request.getParameter("search_combo"));
		String keyword = CommonUtil.nvl(request.getParameter("keyword"));
		String total_count = CommonUtil.nvl(request.getParameter("e_total_count"),"0");
		String curr_page = CommonUtil.nvl(request.getParameter("curr_page"),"1");
		String gubun = CommonUtil.nvl(request.getParameter("gubun"),"");
		
		String s_test_state 	= CommonUtil.nvl(request.getParameter("test_state"),"");
		String s_rating_state 	= CommonUtil.nvl(request.getParameter("rating_state"),"");
		
		String s_member_dist	= CommonUtil.nvl(request.getParameter("s_member_dist"),"");
		
        String[] param= new String[14];
		param[0] = user_id;	
		param[1] = level;	
		param[2] = search_combo;	
		param[3] = keyword;
		param[4] = total_count;
		param[5] = total_count;
		param[6] = "1";
		param[7] = start_date;
		param[8] = end_date;
		param[9] = ent_id;
		param[10] = gubun;	
		param[11] = s_test_state;
		param[12] = s_rating_state;
		param[13] = s_member_dist;
		
		
		Connection con=null;
		ArrayList list =null;
		HashMap listMap = new HashMap();	
		
		try {	
			con = (new CommonConnect()).getConnection_ds1();			
			
			String queryStr = "call sp_sp0501_ent_list3(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";	
			list = DAO.select(con,queryStr,param);	
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			  try{
				  if (con!=null) con.close();
			  }catch(Exception ee){}
		}
		
		
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Excel Download</title>
</head>
<body>
<form name="excel_frm">
<b></b>
</BR>
</BR>
<table width="760" border="1" cellpadding="2" cellspacing="0" bordercolor="C0C0C0" bordercolordark="#FFFFFF" frame=below >
	<tr height="23">
		<td width="50" bgcolor="#D3EBD7" align="center"> 번호 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 소속 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 이름 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 아이디 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 구분 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 회원구분 </td>
	    <td width="160" bgcolor="#D3EBD7" align="center"> 핸드폰 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 이메일 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 응시일 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 종료일 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> 시험상태 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> Rating상태 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> Rating결과 </td>
		<td width="160" bgcolor="#D3EBD7" align="center"> Retest상태 </td>
	</tr>
	<% for (int i=0; i< list.size(); i++) {
		  listMap=(HashMap)list.get(i);
		        
		  r_num = CommonUtil.nvl((String)listMap.get("r_num"));
		  member_id = CommonUtil.nvl((String)listMap.get("member_id"));
		  ent_nm = CommonUtil.nvl((String)listMap.get("ent_nm"));
	      
		  ent_nm = CommonUtil.nvl((String)listMap.get("ent_nm"));
		  login_id_map = CommonUtil.nvl(Crypto.DecodeBySType((String)listMap.get("login_id")));
	      
		  login_name = CommonUtil.nvl((String)listMap.get("login_name"));
	      
		  email = CommonUtil.nvl((String)listMap.get("email"));
		  cell_no = CommonUtil.nvl((String)listMap.get("cell_no"));
	      reg_dt = CommonUtil.nvl((String)listMap.get("reg_dt"));
	      
	      test_state = CommonUtil.nvl((String)listMap.get("test_state"));
	      test_state_str = CommonUtil.nvl((String)listMap.get("test_state_str"));
	      test_state_holding = CommonUtil.nvl((String)listMap.get("test_state_holding"));
	      
	      
	      rating_state = CommonUtil.nvl((String)listMap.get("rating_state"));
	      
	      rerating_member_test_code = CommonUtil.nvl((String)listMap.get("rerating_member_test_code"));
	      rerating_gubun = CommonUtil.nvl((String)listMap.get("rerating_gubun"));
	      rerating_reason = CommonUtil.nvl((String)listMap.get("rerating_reason"));
	      
	      pause_yn = CommonUtil.nvl((String)listMap.get("pause_yn"));
	      test_break_yn = CommonUtil.nvl((String)listMap.get("test_break_yn"));
	      
	      rating_true = CommonUtil.nvl((String)listMap.get("rating_true"));
	      end_dt = CommonUtil.nvl((String)listMap.get("end_dt"));
	      
	      opic_gubun = CommonUtil.nvl((String)listMap.get("gubun"));
	      member_dist_str = CommonUtil.nvl((String)listMap.get("member_dist_str"));
	      
	      rating_grade = CommonUtil.nvl((String)listMap.get("rating_grade"));
	      
	      part_total = CommonUtil.nvl((String)listMap.get("part_total"));
	      
	      if (test_state.equals("R")){
	    	  test_state_str = "환불";
	      }else if (test_state.equals("2")){
	    	  test_state_str = "완료";
	      }else if (test_break_yn.equals("Y")){
	    	  test_state_str = "시험중단";
	      }else if (pause_yn.equals("Y")){
	    	  test_state_str = "일시정지";
	      }else if (test_state.equals("Holding")){
	    	  test_state_str = "보류";
	      }else if (test_state.equals("1")){
	    	  test_state_str = "진행중";
	      }else if (test_state.equals("0")){
	    	  test_state_str = "진행전";
	      
	      }else if (test_state.equals("9")){
	    	  test_state_str = "재시험";
	      }
	      
	%>
	<tr height="23">
		<td align="center"> <%= i+1 %> </td>
	    <td align="center"> <%= ent_nm %> </td>
	    <td align="center"> <%= login_name %> </td>
	    <td align="center"> <%= login_id_map%> </td>
	    
	    <td align="center"> <%= opic_gubun%> </td>
	    <td align="center"> <%= member_dist_str%> </td>
	    
	    <td align="center"> <%= cell_no %> </td>
	    <td align="center"> <%= email %> </td>
	    <td align="center"> <%= reg_dt %> </td>	
	    <td align="center"> <%= end_dt %> </td>		
		<td align="center"> <%=test_state_str %>  
				<%if (rating_true.equals("N")){%>
				<font color="#9400D3" style="font-size:10pt"><b>(무채점)</b></font>
				<%} %>
		</td>
		<td align="center"> 
		<%if(rating_state.equals("1")){ %>
                진행중
        <%}else if (rating_state.equals("2")){%>
                완료
        <%}else if (rating_state.equals("9")){%>
               재시험
        <%}else if (rating_state.equals("Holding")){%>
                홀딩
        <%}else if (rating_state.equals("0") && test_state.equals("2")){ %>
                준비
        <%} %>
		</td>
		<td align="center"> <%=(opic_gubun.equals("TS")&& rating_state.equals("2"))?"Level":""%> <%= rating_grade %><%=(opic_gubun.equals("TS")&& rating_state.equals("2"))?" ("+part_total+"점)":""%> </td>	
		<td align="center"><%=(!rerating_member_test_code.equals(""))?"재시험":"" %></td>
	</tr>
	<% }%>
</table>
</form>
</body>
</html>
